import pandas as pd
import matplotlib.pyplot as plt

def plot_boost_performance(csv_file="boost_bigint_performance.csv", output_file="performance_boost.png"):
    # 读取CSV文件
    df = pd.read_csv(csv_file)
    
    # 画图
    plt.figure(figsize=(10, 6))
    plt.plot(df["Digits"], df["Parsing (ms)"], marker='o', label="Parsing Time")
    plt.plot(df["Digits"], df["Addition (ms)"], marker='s', label="Addition Time")
    plt.plot(df["Digits"], df["String Conversion (ms)"], marker='^', label="String Conversion Time")
    
    # 设置图表标题和标签
    plt.xscale("log")
    plt.yscale("log")
    plt.xlabel("Number of Digits")
    plt.ylabel("Time (ms)")
    plt.title("Boost BigInt Performance Benchmark")
    plt.legend()
    plt.grid(True, which="both", linestyle="--", linewidth=0.5)
    
    # **保存图像**
    plt.savefig(output_file)
    plt.show()

def plot_comparison_performance(csv_file="performance_results.csv", output_file="performance_comparison.png"):
    # **加载数据**
    df = pd.read_csv(csv_file)
    
    # **绘制折线图**
    plt.figure(figsize=(10, 6))
    plt.plot(df["Digits"], df["LinkedList"], marker="o", label="LinkedList")
    plt.plot(df["Digits"], df["String"], marker="s", label="String")
    plt.plot(df["Digits"], df["Array"], marker="^", label="Array")
    plt.plot(df["Digits"], df["Boost"], marker="d", label="Boost")
    
    # **图表信息**
    plt.xlabel("Number of Digits")
    plt.ylabel("Average Time (ms)")
    plt.title("Performance Comparison of Big Integer Addition")
    plt.legend()
    plt.grid(True)
    
    # **保存图像**
    plt.savefig(output_file)
    plt.show()

# 运行两个绘图函数
plot_boost_performance()
plot_comparison_performance()
